package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 赵虎
 * 2020/10/24 1:39 上午
 */
@Controller
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    @RequestMapping(method = RequestMethod.GET)
    public String view() {
        return "resume";
    }

    @RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
    public String edit(@PathVariable("id") Long id, Model model) {
        model.addAttribute("id",id);
        return "resumeEdit";
    }

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add() {
        return "resumeEdit";
    }

    @ResponseBody
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Resume findById(@PathVariable("id") Long id) {
        return resumeService.findById(id);
    }

    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public List<Resume> findList() {
        return resumeService.findList();
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST)
    public Boolean save(@RequestBody Resume resume) {
        return resumeService.save(resume);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.PUT)
    public Boolean update(@RequestBody Resume resume) {
        return resumeService.update(resume);
    }

    @ResponseBody
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public Boolean delete(@PathVariable("id") Long id) {
        return resumeService.delete(id);
    }
}
